#!/bin/bash

host=127.0.0.1
username=mcs
dbname=nstat
pass=******

psqlcmd="-h ${host} -d ${dbname} -U ${username} -t -v ON_ERROR_STOP=1"
#psqlcmd="-d ${dbname} -U ${username} -t -v ON_ERROR_STOP=1"

export PGPASSWORD=$pass;

if [ "$1" != "" ]; then
     ex=$1
     key=-f
#    echo ${ex} | /usr/bin/psql ${psqlcmd} # для ключа -c
    /usr/bin/psql ${psqlcmd} ${key} ${ex}
else
    /usr/bin/psql ${psqlcmd}
fi

unset PGPASSWORD;
